package com.jtalker.server.plugins;

// Dummy PlugIn

import java.lang.reflect.Method;

import com.jtalker.server.JTalkerPlugInInterface;

public class PlugInONE implements JTalkerPlugInInterface {
	private String caller_name = null;
	private String caller_ip = null;

	/** Gets the name of this PlugIn */
	public String getName() {
		return "PlugInONE - dummy plugin";
	}

	/** Gets release # */
	public String getRelease() {
		return "0.0.1";
	}

	/** Gets a full Description for the PlugIn */
	public String getDescription() {
		return "This is a short description of the dummy PlugIn.\nUse this plugin for testing. It provides 3 methods.";
	}

	/** Gets available methods in this PlugIn */
	public Method[] getMethods() {
		Method[] myMethods = new Method[3];

		try {
			myMethods[0] = this.getClass().getDeclaredMethod("addNumbers",
					new Class[] { String.class, String.class });
			myMethods[1] = this.getClass().getDeclaredMethod(
					"getDevelopersName", null);
			myMethods[2] = this.getClass().getDeclaredMethod("getEcho",
					new Class[] { String.class });
		} catch (Exception _e) {
			_e.printStackTrace();
			return null;
		}

		return myMethods;
	}

	/**
	 * Sets user data for calling a method in this user context
	 * 
	 * @param _name
	 *            Users name
	 * @param _ip
	 *            Users IP address
	 */
	public void setCaller(String _name, String _ip) {
		this.caller_name = _name;
		this.caller_ip = _ip;
	}

	// ///////////////////////////////// PlugIn specific Methods
	// /////////////////////////////////////

	/**
	 * This mehod takes two numbers as string and returns the sum
	 * 
	 * @return The result of the addition as string, e.g: "15"
	 */
	public String addNumbers(String _num1, String _num2) {
		return "" + (Double.parseDouble(_num1) + Double.parseDouble(_num2));
	}

	public String getDevelopersName() {
		return "This Plugin was written by ChrM (chrm.info)";
	}

	public String getEcho(String _in) {
		return "User: " + this.caller_name + ", Echo: " + _in;
	}
}
